package com.hopu.blb_erp.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hopu.blb_erp.entity.Order;
import com.hopu.blb_erp.entity.PageEntity;
import com.hopu.blb_erp.entity.TShipping;
import com.hopu.blb_erp.service.OrderService;
import com.hopu.blb_erp.service.ShippingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Api
@RestController
public class ShippingController {

    @Autowired
    private ShippingService shippingService;

    @Autowired
    private OrderService orderService;

    @ApiOperation("查询所有未结算的订单 ")
    @GetMapping("/shippings/{current}/{pageSize}")
    public ResponseEntity<PageEntity<TShipping>> findAllShop(@PathVariable("current")Integer current, @PathVariable("pageSize")Integer pageSize,
                                                             String shippingNumber){
        PageEntity<TShipping> list = shippingService.findPage(current,pageSize,shippingNumber);
        return ResponseEntity.ok(list);
    }

    @ApiOperation("添加发货单信息")
    @PostMapping("/shipping")
    public ResponseEntity<String> findPage(@RequestBody TShipping shipping){
        shippingService.save(shipping);
        Order order = new Order();
        order.setOrderStatus("-3");
        orderService.update(order,new QueryWrapper<Order>().lambda().eq(Order::getOrderId,shipping.getOrderNumber()));
        return ResponseEntity.ok("ok");
    }
}
